import { defineStore } from 'pinia'
import dataJson from './nationality.json'

export const useNationalityStore = defineStore('nationalityStore', {
  state: () => {
    const valueMap = new Map() as Map<string, string>
    const nameMap = new Map() as Map<string, string>
    const data: any = dataJson
    const options = [] as Array<any>
    new Map(Object.entries(data)).forEach((label: any, value) => {
      valueMap.set(value, label.name)
      nameMap.set(label.name, value)
      options.push({ value: label.name, label: label.name })
    })
    return {
      valueMap,
      nameMap,
      options
    }
  },
  actions: {},
  getters: {
    value: (state) => {
      return (label: string) => {
        state.valueMap.get(label)
      }
    },
    label: (state) => {
      return (value: string) => {
        state.nameMap.get(value)
      }
    },
    selectOptions: (state) => state.options
  }
})
